package org.teemor.demo.netty.client.handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.*;
import io.netty.util.concurrent.Promise;

import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @author zhoulk
 * @date 2024/1/9 15:11
 * @desc
 */
public class ImClientHandler extends SimpleChannelInboundHandler {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf in = (ByteBuf) msg;
        int len = in.readableBytes();
        byte[] arr = new byte[len];
        in.getBytes(0, arr);
        System.out.println(new String(arr, StandardCharsets.UTF_8));
        in.release();
    }


//    @Override
//    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
//        Channel channel = ctx.channel();
//
//        channel.writeAndFlush(msg);
//    }

}
